// https://www.nowcoder.com/practice/acead2f4c28c401889915da98ecdc6bf?tpId=230&tqId=2021480&ru=/exam/oj&qru=/ta/dynamic-programming/question-ranking&sourceUrl=/exam/oj?page=1&tab=%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587&topicId=196

// 算法思路总结：
// 1. 前缀和算法快速求解区间和查询
// 2. 预处理：dp[i]表示前i个元素的和
// 3. 区间和计算：[l,r]区间和 = dp[r] - dp[l-1]
// 4. 预处理时间复杂度：O(n)，查询时间复杂度：O(1)
// 5. 空间复杂度：O(n)

#include <iostream>
using namespace std;

const int N = 100010;
long long dp[N], arr[N];

int main() 
{
    int n, m;
    cin >> n >> m;

    for (int i = 1 ; i <= n ; i++)
    {
        cin >> arr[i];
        dp[i] = dp[i - 1] + arr[i];
    }

    for (int i = 0 ; i < m ; i++)
    {
        int l, r;
        cin >> l >> r;
        cout << dp[r] - dp[l - 1] << endl;
    }

    return 0;
}